package exemples.corba.callback;

import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;

import exemples.corba.callback.CallbackApp.Bonjour;
import exemples.corba.callback.CallbackApp.BonjourCallback;
import exemples.corba.callback.CallbackApp.BonjourHelper;
import exemples.corba.callback.CallbackApp.BonjourPOA;






class BonjourServant extends BonjourPOA
{
    public void say(BonjourCallback callobj, String msg)
    {
        callobj.callback(msg);
        System.out.println("Servant : Callback effectue\n");
    }
}


public class BonjourServer 
{
    public static void main(String args[]) 
    {
	try { 
	    ORB orb = ORB.init(args, null); 

	    POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));  
	    rootpoa.the_POAManager().activate(); 

	    BonjourServant bonjourImpl = new BonjourServant();

	    org.omg.CORBA.Object ref = rootpoa.servant_to_reference(bonjourImpl);
	    Bonjour cref = BonjourHelper.narrow(ref);

	    org.omg.CORBA.Object objRef = 
		           orb.resolve_initial_references("NameService");
	    NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

	    String name = "Bonjour";
	    NameComponent path[] = ncRef.to_name(name);
	    ncRef.rebind(path, cref);
	    
	    orb.run();
	}
	    
	catch(Exception e) {
	    System.err.println("ERROR : " + e);
	    e.printStackTrace(System.out);
	}
    }
}
